package com.hui.xiao.xiaohui.view;

import android.app.Activity;
import android.media.Image;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterViewFlipper;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.hui.xiao.xiaohui.R;

/**
 * Created by Administrator on 2016/5/20.
 */
public class AdapterViewFilpperTest extends Activity {
    int[] images = new int[]{
            R.drawable.bkch, R.drawable.logo, R.drawable.aboc,
            R.drawable.bkch, R.drawable.logo, R.drawable.aboc,
            R.drawable.bkch, R.drawable.logo, R.drawable.aboc
    };
    AdapterViewFlipper flipper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.adapter_view_filpper);
        flipper = (AdapterViewFlipper) findViewById(R.id.flipper);
        BaseAdapter adapter = new BaseAdapter() {
            @Override
            public int getCount() {
                return images.length;
            }

            @Override
            public Object getItem(int position) {
                return position;
            }

            @Override
            public long getItemId(int position) {
                return position;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                ImageView imageView = new ImageView(AdapterViewFilpperTest.this);
                imageView.setImageResource(images[position]);
                imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
                return imageView;
            }
        };
        flipper.setAdapter(adapter);
    }

    public void prev(View view) {
        flipper.showPrevious();
        flipper.stopFlipping();
    }

    public void next(View view) {
        flipper.showNext();
        flipper.stopFlipping();
    }

    public void auto(View view) {
        flipper.startFlipping();
    }
}
